package org.mili.ticketeer.service;

import org.mili.application.dao.DaoFactory;
import org.mili.application.dao.ModificationResult;
import org.mili.application.service.Service;
import org.mili.application.service.ServiceException;
import org.mili.ticketeer.dao.PriorityDao;
import org.mili.ticketeer.dto.Priority;
import org.mili.application.util.Lambda;

import java.util.List;

public class PriorityService extends Service {
	private PriorityDao _priorityDao = DaoFactory.getDao(PriorityDao.class);

    public ModificationResult write(final Priority priority) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _priorityDao.write(priority);
            }
        });
    }

    public Priority findByName(final String name) throws ServiceException {
        return doReadInService(new Lambda<Priority>() {
            @Override
            public Priority exec(Object... params) throws Exception {
                return _priorityDao.findByName(name);
            }
        });
    }

    public Priority findById(final int id) throws ServiceException {
        return doReadInService(new Lambda<Priority>() {
            @Override
            public Priority exec(Object... params) throws Exception {
                return _priorityDao.findById(id);
            }
        });
    }

    public ModificationResult delete(final Priority priority) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _priorityDao.delete(priority);
            }
        });
    }

    public List<Priority> getPriorities() throws ServiceException {
        return doReadInService(new Lambda<List<Priority>>() {
            @Override
            public List<Priority> exec(Object... params) throws Exception {
                return _priorityDao.getPriorities();
            }
        });
    }


}
